﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using HotelSoft.HotelManagement_DAO;

namespace HotelSoft.HotelManagement_BUS
{
    class AccountBUS
    {
        public static DataTable AccountList()
        {
            return AccountDAO.SelectAll();
        }

        public static int LoginAccount(AccountDTO ACC)
        {
            DataTable tblAcc = new DataTable();
            tblAcc = AccountList();
            foreach (DataRow tk in tblAcc.Rows)
            {
                if (tk["Username"].ToString().ToUpper().Equals(ACC.USERNAME.ToUpper()) && tk["Password"].ToString().Equals(ACC.PASSWORD))
                {
                    if (tk["Role"].ToString() == "gd")
                        return 1;
                    else
                        if (tk["Role"].ToString() == "ql")
                            return 2;
                        else 
                            if (tk["Role"].ToString() == "tt")
                                return 3;
                            else
                                return 4;
                }
            }
            return 0;
        }

        public static bool ChangePassword(string Username, string Password, string NewPass)
        {
            DataTable tblAcc = new DataTable();
            tblAcc = AccountList();
            foreach (DataRow tk in tblAcc.Rows)
            {
                if (tk["Username"].ToString().ToUpper().Equals(Username.ToUpper()) && tk["Password"].ToString().Equals(Password))
                {
                    return AccountDAO.Update(Username, NewPass);
                }
            }
            return false;
        }

        public static bool InsertAccount(AccountDTO ACC)
        {
            return AccountDAO.Insert(ACC);
        }

        public static bool DeleteAccount(AccountDTO ACC)
        {
            return AccountDAO.Delete(ACC);
        }

        public static bool CheckUsername(AccountDTO ACC)
        {
            return AccountDAO.CheckUsername(ACC);
        }
    }
}
